package com.integration.gateway;

import com.integration.gateway.pojo.DrinkType;
import com.integration.gateway.pojo.Order;
import com.integration.gateway.pojo.OrderItem;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Slf4j
@Component
public class Trigger {



    @Autowired
    private Cafe cafe;

    //@Before
    public Order assumeOrder(){
        Order order = new Order();
        OrderItem orderItem1 = new OrderItem();
        orderItem1.setOrderNumber(1);
        orderItem1.setDrinkType(DrinkType.LATTE);
        orderItem1.setIced(true);
        orderItem1.setShots(2);
        OrderItem orderItem2 = new OrderItem();
        orderItem2.setOrderNumber(2);
        orderItem2.setDrinkType(DrinkType.MOCHA);
        orderItem2.setIced(false);
        orderItem2.setShots(3);

        OrderItem orderItem3 = new OrderItem();
        orderItem3.setOrderNumber(3);
        orderItem3.setGoodName("Coupon: $100");
        order.getOrderItems().add(orderItem1);
        order.getOrderItems().add(orderItem2);
        order.getOrderItems().add(orderItem3);
        return order;
    }

    //@PostConstruct
    @Scheduled(cron="0 0/1 * * * ?")
    public void triggerChanelTransfer(){
        log.info("===   placeOrder  ===");
        cafe.placeOrder(assumeOrder());
    }
}
